package com.example.chat.config;


import com.example.chat.client.ChatWebClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
import org.springframework.web.service.invoker.HttpServiceProxyFactory;

import java.time.Duration;


@Configuration
public class ChatWebClientBuilder {
    private final String url = "https://aip.baidubce.com";
    @Bean
    public ChatWebClient createClient(WebClient.Builder webClientBuilder){
        WebClient client = webClientBuilder.baseUrl(url).build();
        return HttpServiceProxyFactory
                .builder()
                .blockTimeout(Duration.ofSeconds(2000))
                .clientAdapter(WebClientAdapter.forClient(client))
                .build()
                .createClient(ChatWebClient.class);
    }
}